




/*
'===============================================================================
'  HNG.Portal.BL.TblThuocTinhSanPhamManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblThuocTinhSanPhamManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_IdsanPham="IdsanPham";
				
				public const String Field_Title="Title";
				
				public const String Field_Value="Value";
				
				public const String Field_TrangThai="TrangThai";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblThuocTinhSanPhamManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_IdsanPham,typeof(int));
			
						
			
			dt.Columns.Add(Field_Title,typeof(string));
			
						
			
			dt.Columns.Add(Field_Value,typeof(string));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
			            
            return dt;			
		}
			
		public TblThuocTinhSanPhamEntity Convert_Entity(TblThuocTinhSanPhamEntity _TblThuocTinhSanPhamEntity,TblThuocTinhSanPhamEntity _TblThuocTinhSanPhamEntity_XML)
		{	
			
				
			_TblThuocTinhSanPhamEntity.Id= _TblThuocTinhSanPhamEntity_XML.Id;
				
			_TblThuocTinhSanPhamEntity.IdsanPham= _TblThuocTinhSanPhamEntity_XML.IdsanPham;
				
			_TblThuocTinhSanPhamEntity.Title= _TblThuocTinhSanPhamEntity_XML.Title;
				
			_TblThuocTinhSanPhamEntity.Value= _TblThuocTinhSanPhamEntity_XML.Value;
				
			_TblThuocTinhSanPhamEntity.TrangThai= _TblThuocTinhSanPhamEntity_XML.TrangThai;
				
			
			return _TblThuocTinhSanPhamEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblThuocTinhSanPhamEntity Insert(TblThuocTinhSanPhamEntity TblThuocTinhSanPhamEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblThuocTinhSanPhamEntity, true);
			}
			return TblThuocTinhSanPhamEntity;
		}

		
		public TblThuocTinhSanPhamEntity Insert(int Id, int IdsanPham, string Title, string Value, bool TrangThai)
		{
			TblThuocTinhSanPhamEntity _TblThuocTinhSanPhamEntity = new TblThuocTinhSanPhamEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblThuocTinhSanPhamEntity.Id = Id;
				_TblThuocTinhSanPhamEntity.IdsanPham = IdsanPham;
				_TblThuocTinhSanPhamEntity.Title = Title;
				_TblThuocTinhSanPhamEntity.Value = Value;
				_TblThuocTinhSanPhamEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblThuocTinhSanPhamEntity, true);
			}
			return _TblThuocTinhSanPhamEntity;
		}

		public TblThuocTinhSanPhamEntity Insert(int IdsanPham, string Title, string Value, bool TrangThai)
		{
			TblThuocTinhSanPhamEntity _TblThuocTinhSanPhamEntity = new TblThuocTinhSanPhamEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblThuocTinhSanPhamEntity.IdsanPham = IdsanPham;
				_TblThuocTinhSanPhamEntity.Title = Title;
				_TblThuocTinhSanPhamEntity.Value = Value;
				_TblThuocTinhSanPhamEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblThuocTinhSanPhamEntity, true);
			}
			return _TblThuocTinhSanPhamEntity;
		}

		public bool Update(TblThuocTinhSanPhamEntity _TblThuocTinhSanPhamEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblThuocTinhSanPhamFields.Id == _TblThuocTinhSanPhamEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblThuocTinhSanPhamEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblThuocTinhSanPhamEntity _TblThuocTinhSanPhamEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblThuocTinhSanPhamEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int IdsanPham, string Title, string Value, bool TrangThai)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblThuocTinhSanPhamEntity _TblThuocTinhSanPhamEntity = new TblThuocTinhSanPhamEntity(Id);
				if (adapter.FetchEntity(_TblThuocTinhSanPhamEntity))
				{
				
					_TblThuocTinhSanPhamEntity.IdsanPham = IdsanPham;
					_TblThuocTinhSanPhamEntity.Title = Title;
					_TblThuocTinhSanPhamEntity.Value = Value;
					_TblThuocTinhSanPhamEntity.TrangThai = TrangThai;
					adapter.SaveEntity(_TblThuocTinhSanPhamEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblThuocTinhSanPhamEntity _TblThuocTinhSanPhamEntity = new TblThuocTinhSanPhamEntity(Id);
				if (adapter.FetchEntity(_TblThuocTinhSanPhamEntity))
				{
					adapter.DeleteEntity(_TblThuocTinhSanPhamEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblThuocTinhSanPhamEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblThuocTinhSanPhamEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByIdsanPham(int IdsanPham)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.IdsanPham == IdsanPham);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblThuocTinhSanPhamEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTitle(string Title)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.Title == Title);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblThuocTinhSanPhamEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByValue(string Value)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.Value == Value);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblThuocTinhSanPhamEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblThuocTinhSanPhamEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblThuocTinhSanPhamEntity SelectOne(int Id)
		{
			TblThuocTinhSanPhamEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblThuocTinhSanPhamEntity _TblThuocTinhSanPhamEntity = new TblThuocTinhSanPhamEntity(Id);
				if (adapter.FetchEntity(_TblThuocTinhSanPhamEntity))
				{
					toReturn = _TblThuocTinhSanPhamEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection( new TblThuocTinhSanPhamEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThuocTinhSanPhamCollection, null, 0, null);
			}
			return _TblThuocTinhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThuocTinhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThuocTinhSanPhamCollection, filter, 0, null);
			}
			return _TblThuocTinhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThuocTinhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByIdsanPham(int IdsanPham)
		{
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.IdsanPham == IdsanPham);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThuocTinhSanPhamCollection, filter, 0, null);
			}
			return _TblThuocTinhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdsanPhamRDT(int IdsanPham)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.IdsanPham == IdsanPham);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThuocTinhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTitle(string Title)
		{
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.Title == Title);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThuocTinhSanPhamCollection, filter, 0, null);
			}
			return _TblThuocTinhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTitleRDT(string Title)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.Title == Title);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThuocTinhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByValue(string Value)
		{
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.Value == Value);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThuocTinhSanPhamCollection, filter, 0, null);
			}
			return _TblThuocTinhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByValueRDT(string Value)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.Value == Value);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThuocTinhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblThuocTinhSanPhamCollection, filter, 0, null);
			}
			return _TblThuocTinhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblThuocTinhSanPhamCollection = new EntityCollection(new TblThuocTinhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblThuocTinhSanPhamFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblThuocTinhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
